<?php

include("../tuggo.inc.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<title>TUGGO &raquo; Installation</title>

<style type="text/css">
@import url(../admin/style.css);
</style>

</head>
<body>
<div id="container">
<div style='background: #B3CAE2; border-bottom: 2px solid #708AA7; padding: 10px; text-align: right;'>
<table class="ii" cellspacing="0" cellpadding="0">
	<tr>
		<td class="iileft" style="font-weight: bold;">TUGGO <span style='font-size: 9px;'>(alpha)</span> Installation <?php echo SYSVERSION; ?></td>
		<td class="iiright"><a style="text-decoration: underline;" href="<?php echo SYSURL; ?>"><img src="../admin/logo2.png" alt="" style="width: 20px;" /></a></td>
	</tr>
</table></div>

<div id="admincontent">




<?php 
$act = $_GET['act'];
if($act == "") { ?>





	<h2>TUGGO Installation</h2>
	<div style="padding: 10px;">Ready to install TUGGO, an open source website management system?  This will guide you through all of the steps that must be taken to complete the installation process allowing you to easily manage your new website!  Once this process is complete you will be able to login to your admin contol panel with the username and password which will be defined in the next step of this process.  To complete the process you will need the following:<br/><br/>
	
	<table class="ii" cellpadding="0" cellspacing="0">
		<tr>
			<td class="iileft" style="padding: 5px; width: 60px;">
				<img style="width: 60px;" src="../admin/logo3.png" alt="" />
			</td>
			<td class="iiright" style="text-align: left;">
				<ul>
					<li>MySQL Database</li>
					<li>MySQL Access Username &amp; Password</li>
					<li>Common Sense...</li>
				</ul>
			</td>
		</tr>
	</table>
	
	<br/><br/>
	
	Before you can install your copy of TUGGO you ust agree to the following terms of service and comply to all lawsgoverning your area.  If you have any questions please contact us before installing TUGGO.  Once you have reviewed these terms of service and agree to them please click the button below to proceed to step two.
	
	<br/><br/>
	
	<div id="check" style="font-weight: bold; text-align: center;">
		Terms of Service
	</div>
	<div style="border: 1px solid #A2A2A2; background: #F5F5F5; padding: 10px; width: 97.2%; height: 150px; overflow: auto; margin-top: 3px;"><?php include("../admin/license.php"); ?><br/></div>
	
	<br/><br/>
	
	<div style="border: 1px solid #CCCCCC; background: #F0F0EE; text-align: center; padding: 5px;"><a href="index.php?act=step2">I agree, proceed to the next step &raquo;</a></div>
	</div>




<?php } elseif($act == "step2") { ?>






	<h2>TUGGO Installation - Step 2</h2>
	<div style="padding: 10px;">
	
	 <?php $files = array(
    		2 => "index.php",
    		3 => "login.php",
    		5 => "templates/header.php",
    		6 => "templates/index.php",
    		7 => "templates/footer.php",
    		8 => "templates/style.css",
    		9 => "tuggo.inc.php",
    		11 => "admin/header.php",
    		12 => "admin/footer.php",
    		13 => "admin/tuggo.php",
    		14 => "admin/index.php",
    		15 => "admin/pages.php",
    		16 => "admin/news.php",
    		10 => "admin/categories.php",
    		17 => "admin/nav.php",
    		18 => "admin/templates.php",
    		19 => "admin/accounts.php",
    		20 => "admin/system.php",
    		21 => "admin/loginstyle.css",
    		22 => "admin/style.css"
    ) ?>
	
	<table id="data" cellspacing="3" cellpadding="0" style="width: 100%;">
	<tr>
		<td style="width: 2px; background: #ECECEC url(../admin/images/tabletop.png) repeat-x;">ID</td>
		<td style="background: #ECECEC url(../admin/images/tabletop.png) repeat-x;">Filename</td>
		<td style="width: 200px; background: #ECECEC url(../admin/images/tabletop.png) repeat-x; text-align: center;">Status</td>
		<td style="width: 16px; text-align: center; background: #ECECEC url(../admin/images/tabletop.png) repeat-x;">&nbsp;</td>
	</tr>
	<?php
	
	foreach ($files as $key => $value) {
	?>
	<?php if (file_exists("../" . $value)) { ?>
	<tr>
		<td style="text-align: center;"><?php echo $key; ?></td>
		<td><?php echo $value; ?></td>
		<td>
			<span style="color: #27962B;">File Exists!</span>	
		</td>
		<td style="text-align: center;">
			<a href="http://files.tuggo.org/?file=<?php echo $value; ?>"><img src="../admin/images/page_go.png" alt=""/></a>
		</td>
	</tr>
	
	<?php } else { ?>
	
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D; text-align: center;"><?php echo $key; ?></td>
		<td style="border: 1px solid #881616; background: #E46D6D;"><?php echo $value; ?></td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR!  File does not exist!</td>
		<td style="border: 1px solid #881616; background: #E46D6D; text-align: center;">
			<a href="http://files.tuggo.org/?file=<?php echo $value; ?>"><img src="../admin/images/page_go.png" alt=""/></a>
		</td>
	</tr>
	
	<?php } ?>
	<?php } ?>
	</table>
	
	<br/>
	
	If all of your files have been uploaded (none of the row are red) then you are all set to continue to the next step.  To do this, please click the button below.  If you have a red colored row it is reccomended that you upload the missing files to your webserver, however if you like, you may continue anyway.<br/><br/>
	
	<div style="border: 1px solid #CCCCCC; background: #F0F0EE; text-align: center; padding: 5px;"><a href="index.php?act=step3">Proceed to the next step &raquo;</a></div>
	
	</div>





<?php } elseif($act == "step3") { ?>




	<h2>TUGGO Installation - Step 3</h2>
	<div style="padding: 10px;">
	
	<script type="text/javascript">
		var runningversion = "<?php echo SYSVERSION; ?>";
	</script>
	<script src="http://static.tuggo.org/remote/installvercheck.js" type="text/javascript"></script>


	<br/>
	
	The status of the version of TUGGO that you are currently installing is stated above from a remote server.  If you have chosen this release of TUGGO on purpose than please proceed with the installation by clicking thel ink below.  If you need to download the latest release, please <a href="http://tuggo.org">click here</a> to go to the TUGGO website.  Otherwise continue with the installation!
	
	<br/><br/>
	
	<div style="border: 1px solid #CCCCCC; background: #F0F0EE; text-align: center; padding: 5px;"><a href="index.php?act=step4">Proceed to the next step &raquo;</a></div>
	
	</div>
	
	
	

<?php } elseif($act == "step4") { ?>




	<form name="f1" method="POST" action="index.php?act=step5">

	<h2>TUGGO Installation - Step 4</h2>
	<div style="padding: 10px;">
	
	Please complete the following fields with the settings from your server.  These are most likely provided by your host, but if not then you should contact them and/or check out the <a href="http://support.tuggo.org">TUGGO support center</a>.
	<br/><br/>
	
	<table class="ii" cellpadding="0" cellspacing="0">
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Database:
			</td>
			<td class="iiright">
				<input type="text" name="mysqldatabase" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Username:
			</td>
			<td class="iiright">
				<input type="text" name="mysqlusername" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Password:
			</td>
			<td class="iiright">
				<input type="password" name="mysqlpassword" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Host:
			</td>
			<td class="iiright">
				<input type="text" name="mysqlhost" style="width: 98.0%;" value="localhost" />
			</td>
		</tr>
		
		<tr>
			<td colspan="2">
				<br/>
				
				The next step is the administration user information.  Please complete the form with the settings that you would like to use to login to your new admin control panel for your website.
				
				<br/><br/>
			</td>
		</tr>
		
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				Admin Username:
			</td>
			<td class="iiright">
				<input type="text" name="adminusername" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				Admin Password:
			</td>
			<td class="iiright">
				<input type="password" name="adminpassword" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				Admin Password (again):
			</td>
			<td class="iiright">
				<input type="password" name="adminpassword2" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				System Email:
			</td>
			<td class="iiright">
				<input type="text" name="sysemail" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				&nbsp;
			</td>
			<td class="iiright">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" style="background: #F0F0EE; width: 200px; font-size: 10px;" value="Start Over" />
			</td>
		</tr>
	</table>

	<input value="Proceed to the next step &raquo;" type="submit" style="font-size: 10px; border: 1px solid #CCCCCC; background: #F0F0EE; text-align: center; padding: 5px; width: 100%;">

	</div>
	</form>



<?php } elseif($act == "step5") { ?>



		<?php
		$mysqldatabase = $_POST['mysqldatabase'];
		$mysqlusername = $_POST['mysqlusername'];
		$mysqlpassword = $_POST['mysqlpassword'];
		$mysqlhost = $_POST['mysqlhost'];
		
		$adminusername = $_POST['adminusername'];
		$adminpassword = $_POST['adminpassword'];
		$adminpassword2 = $_POST['adminpassword2'];
		$sysemail = $_POST['sysemail'];
		
		if($mysqldatabase == "" || $mysqlusername == "" || $mysqlpassword == "" || $mysqlhost == "" || $adminusername == "" || $adminpassword == "" || $adminpassword != $adminpassword2 || $sysemail == "") { ?>
		
		
	<form name="f1" method="POST" action="index.php?act=step5">

	<h2>TUGGO Installation - Step 4</h2>
	<div id="error"><img src="../admin/images/alert.png" alt="Error!" style="float: left;" />&nbsp;There was an error, please review your entry before you submit it again.</div>

	<div style="padding: 10px;">
	
	Please complete the following fields with the settings from your server.  These are most likely provided by your host, but if not then you should contact them and/or check out the <a href="http://support.tuggo.org">TUGGO support center</a>.
	<br/><br/>
	
	<table class="ii" cellpadding="0" cellspacing="0">
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Database:
			</td>
			<td class="iiright">
				<input type="text" name="mysqldatabase" style="width: 98.0%;" value="<?php echo $mysqldatabase; ?>" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Username:
			</td>
			<td class="iiright">
				<input type="text" name="mysqlusername" style="width: 98.0%;" value="<?php echo $mysqlusername; ?>" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Password:
			</td>
			<td class="iiright">
				<input type="password" name="mysqlpassword" style="width: 98.0%;" value="<?php echo $mysqlpassword; ?>" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				MySQL Host:
			</td>
			<td class="iiright">
				<input type="text" name="mysqlhost" style="width: 98.0%;" value="<?php echo $mysqlhost; ?>" />
			</td>
		</tr>
		
		<tr>
			<td colspan="2">
				<br/>
				
				The next step is the administration user information.  Please complete the form with the settings that you would like to use to login to your new admin control panel for your website.
				
				<br/><br/>
			</td>
		</tr>
		
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				Admin Username:
			</td>
			<td class="iiright">
				<input type="text" name="adminusername" style="width: 98.0%;" value="<?php echo $adminusername; ?>" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				Admin Password:
			</td>
			<td class="iiright">
				<input type="password" name="adminpassword" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				Admin Password (again):
			</td>
			<td class="iiright">
				<input type="password" name="adminpassword2" style="width: 98.0%;" value="" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				System Email:
			</td>
			<td class="iiright">
				<input type="text" name="sysemail" style="width: 98.0%;" value="<?php echo $sysemail; ?>" />
			</td>
		</tr>
		<tr>
			<td class="iileft" style="padding-right: 5px; text-align: right;">
				&nbsp;
			</td>
			<td class="iiright">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" style="background: #F0F0EE; width: 200px; font-size: 10px;" value="Start Over" />
			</td>
		</tr>
	</table>

	<input value="Proceed to the next step &raquo;" type="submit" style="font-size: 10px; border: 1px solid #CCCCCC; background: #F0F0EE; text-align: center; padding: 5px; width: 100%;">

	</div>
	</form>



			<?php } else { ?>
			
			
			
			<h2>TUGGO Installation - Step 5</h2>
			<div id="check"><img src="../admin/images/check.png" alt="Error!" style="float: left;" />&nbsp;Perfect!</div>
	
			<br/>
			
			Your database information has been confirmed and it will now be setup to work with TUGGO...
			
			<br/><br/>
			
			<?php 
			$username = $mysqlusername; // MySQL Username (type between quotes!)
			$password = $mysqlpassword; // MySQL Password (type between quotes!)
			$host = $mysqlhost; // MySQL Host (type between quotes!)
			$db = $mysqldatabase; // MySQL Database (type between quotes!)

			/* Connect to the database using variables defined above */
			$connect = mysql_connect($host, $username, $password) 
				or die("Could not connect to MySQL server!");

			/* Select the database after connecting to the database */
			$selected = mysql_select_db($db,$connect) 
				or die("Could not select the database!");
			?>
				
				
<table id="data" cellspacing="3" cellpadding="0" style="width: 100%;">
	<tr>
		<td style="background: #ECECEC url(../admin/images/tabletop.png) repeat-x;">Process</td>
		<td style="width: 200px; background: #ECECEC url(../admin/images/tabletop.png) repeat-x; text-align: center;">Status</td>
	</tr>
	
	
<?php $result = mysql_query('DROP TABLE IF EXISTS `users`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Users</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Users</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `users` (`id` int(11) NOT NULL auto_increment, `username` text NOT NULL, `password` text NOT NULL, `email` text NOT NULL, `displayname` text NOT NULL, `nickname` text NOT NULL, `about` text NOT NULL, `aim` text NOT NULL, `msn` text NOT NULL, `yim` text NOT NULL, `gtalk` text NOT NULL, `url` text NOT NULL, PRIMARY KEY  (`id`) ) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Users</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Users</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query("INSERT INTO `users` VALUES (1, '" . $adminusername . "', '" . md5($adminpassword) . "', '', 'New User', '', '', '', '', '', '', '');");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Administrator</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Administrator</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `templates`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Templates</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Templates</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `templates` ( `id` int(11) NOT NULL auto_increment, `name` text NOT NULL, `file` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Templates</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Templates</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `pages`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Pages</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Pages</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `pages` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `path` text NOT NULL, `wwwpath` text NOT NULL, `content` text NOT NULL, `lastupdate` text NOT NULL, PRIMARY KEY  (`id`) ) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Pages</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Pages</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query("INSERT INTO `pages` VALUES (1, 'Home', '', '', 'This is the homepage of your new TUGGO installation.  Feel free to login to your admin control panel and edit it!', 'Thursday, August 10, 2006');");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Instert Data: Homepage</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Instert Data: Homepage</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `nav`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Navigation</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Navigation</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>
<?php $result = mysql_query('CREATE TABLE `nav` ( `id` int(11) NOT NULL auto_increment, `name` text NOT NULL, `link` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Navigation</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Navigation</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query("INSERT INTO `nav` VALUES (1, 'Home', 'index.php');");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Home Navigation Link</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Home Navigation Link</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `logs`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Logs</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Logs</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `logs` ( `id` int(11) NOT NULL, `title` text NOT NULL, `user` text NOT NULL, `oldcontent` text NOT NULL, `newcontent` text NOT NULL, `date` text NOT NULL, `time` text NOT NULL) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Logs</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Logs</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `config`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Configuration</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Configuration</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `config` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `display` text NOT NULL, `type` text NOT NULL, `value` text NOT NULL, `cat` int(11) NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Configuration</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Configuration</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>


<?php
$root = substr($_SERVER['SCRIPT_NAME'],0, -17);
$root = 'http://'.$_SERVER['SERVER_NAME'].$root; 
?>

<?php

$result = mysql_query("INSERT INTO `config` VALUES (1, 'sitename', 'Site Name', 'textbox', 'New Website', 999);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Website Name</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Website Name</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }

$result = mysql_query("INSERT INTO `config` VALUES (2, 'siteurl', 'Site URL', 'textbox', '" . $root . "', 999);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Site URL</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Site URL</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }


$result = mysql_query("INSERT INTO `config` VALUES (3, 'sysemail', 'System Email Address', 'textbox', '" . $sysemail . "', 999);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: System Email Address</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: System Email Address</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (5, 'online', 'Website Online?', 'dropdown', '1', 998);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Online/Offline Settings</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Online/Offline Settings</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (6, 'offlinemessage', 'Offline Message', 'textarea', 'Sorry, this website is currently offline while we make some changes.  Please try accessing our site again later.', 998);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Offline Message</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Offline Message</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (8, 'description', 'Site Description', 'textarea', '', 997);");

	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Site Description</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Site Description</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (9, 'author', 'Site Author', 'textbox', '', 997);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Site Author</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Site Author</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (10, 'keywords', 'Keywords (Seperate with commas)', 'textbox', '', 997);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Keywords</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Keywords</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (11, 'adminnotes', 'Admin Notes', 'none', 'These are your admin notes and they can be used to track users, tasks, and even what you are doing for dinner tonight!  You choose!', 7);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Admin Notes</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Admin Notes</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (999, 'main', 'Main Configuration', 'cat', '', 0);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Main Category</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Main Category</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }
$result = mysql_query("INSERT INTO `config` VALUES (997, 'meta', 'META', 'cat', '', 0);");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: META Category</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: META Category</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php }

$result = mysql_query("INSERT INTO `config` VALUES (998, 'onlinesettings', 'Online Settings', 'cat', '', 0);");


	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Online/Offline Settings Category</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Online/Offline Settings Category</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `blog`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Blog</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Blog</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `blog` (`id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `category` text NOT NULL, `author` text NOT NULL, `content` text NOT NULL, `status` text NOT NULL, `lastupdate` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Blog</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Blog</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query("INSERT INTO `blog` VALUES (1, 'The First Blog Post', 'none', 'The TUGGO Group', 'This is the first blog post on your blog.  You may choose to edit or delete this through the admin control panel.', 'yes', 'Thursday, August 10, 2006');");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: Blog Post</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: Blog Post</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('DROP TABLE IF EXISTS `cats`;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Drop Table: Categories</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Drop Table: Categories</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query('CREATE TABLE `cats` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `description` text NOT NULL, `parent` text NOT NULL, `lastupdate` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM;');
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Create Table: Categories</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Create Table: Categories</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php $result = mysql_query("

INSERT INTO `cats` VALUES (1, 'Uncategorized', '', 'none', '');");
	if (!$result) { ?>
	<tr>
		<td style="border: 1px solid #881616; background: #E46D6D;">Insert Data: First Category</td>
		<td style="border: 1px solid #881616; background: #E46D6D;">ERROR: Query Problem</td>
	</tr>
	<?php } else { ?>
	<tr>
		<td>Insert Data: First Category</td>
		<td><span style="color: #27962B;">Success!</span></td>
	</tr>
<?php } 
 ?>

<?php

$to = $sysemail;
$subject = "TUGGO Installation  (Powered by TUGGO)";

	$message = "Thank you for choosing TUGGO as the content management system for your website.  The installation process is now complete and you may proceed with creating and managing website pages, news, and more!  Here is the information that you will need to do this: \n \nUsername: " . $adminusername . "\nPassword: " . $adminpassword . "\n\n<a href='http://tuggo.org'>Visit the TUGGO website for more information!</a>\n\nOnce again, we would like to thank you for choosing TUGGO as your content management system.  Even though you have already reviewed our terms of service, please review them as we reserve the right to chage them without notice.  We also have many other resources to improve your website in our web portal.\n\nSincerely,\nThe TUGGO Group\n<a href='http://tuggo.org'>www.TUGGO.org</a>";

$from = "system@tuggo.org";
$headers = "From: $from";
mail($to,$subject,$message,$headers);


$replace = "
<?php

################################################################################
#+============================================================================+#
#+ Powered by TUGGO Open Source Content Mangement System (www.TUGGO.org)	  +#
#+ Code in this package is subject to the liscence in the root directory.	  +#
#+============================================================================+#
#+ TUGGO (beta) 1.0  |  Developed by Paul Cheek (pcheek@tuggo.org)			  +#
#+============================================================================+#
################################################################################


// This is a system geerated configuration file.  It is reccomended that you do
// not make any changes to this file unless you know what you are doing or you
// have been instructed to do so by a member of the TUGGO Group.  Enjoy!

define('SYSNAME', 'TUGGO'); // System name
define('SYSURL', 'http://tuggo.org'); // System website url
define('SYSVERSION', '1.0'); // Currently running version of the system

define('INSTALLED', true); // Is the system already installed?

define('MYSQLUSERNAME', '" . $mysqlusername . "'); // MySQL connection username
define('MYSQLPASSWORD', '" . $mysqlpassword . "'); // MySQL connection password
define('MYSQLDATABASE', '" . $mysqldatabase . "'); // MySQL connection database
define('MYSQLHOST', '" . $mysqlhost . "'); // MySQL connection host (most likely 'localhost')

?>
";

chmod("../tuggo.inc.php", 0755);

$file = fopen("../tuggo.inc.php", 'wb');
fwrite($file, $replace);
fclose($file);

chmod("../tuggo.inc.php", 0666);
?>

</table>

<br/>

Your database has been setup assuming that there are not any red columns in the table above.  If there are you should contact the TUGGO group before proceeding.  If not you may continue to the next, and final step!

<br/><br/>

<div style="border: 1px solid #CCCCCC; background: #F0F0EE; text-align: center; padding: 5px;"><a href="index.php?act=step6&username=<?php echo $adminusername; ?>">Proceed to the next (final) step &raquo;</a></div>
			
			<?php } ?>




<?php } elseif($act == "step6") { ?>




	<h2>TUGGO Installation: Complete!</h2>
	<div id="check"><img src="../admin/images/check.png" alt="Error!" style="float: left;" />&nbsp;Boo ya!  The installation process is now complete!</div>

	<br/>
	
	The installation process of TUGGO is complete!  Your website is now setup and running and you can login to your admin control panel <a href="../admin/">here</a>.  Before you begin using your website please make sure that you have configured everything in the settings.php file so that images and links will correctly function.<br/><br/>
	
	<div id="error"><b>WARNING:</b> Before you begin using TUGGO make sure you remove the /install/ directory since this is a major security risk!</div>
	
	<br/>
	
	<i><b>Here is some useful information to help you get your website setup...</b></i><br/>
	
	<ul>
		<li><a href="../">Your Website</a></li>
		<li><a href="../admin/">Admin Control Panel</a></li>
		<li><a href="../login.php">Login Page</a></li>
		<li><a href="../?function=blog">Blog</a></li>
		<br/><br/>
		<li>Username: <?php echo $_GET['username']; ?></li>
		<li>Password: Emailed to you.</li>
		<br/><br/>
		<li><a href="http://tuggo.org">TUGGO.org</a></li>
		<li><a href="http://forum.tuggo.org">Support Forums</a></li>
		<li><a href="http://wiki.tuggo.org">Knowledgebase</a></li>
	</ul>
	
	<br/>
	
	We hope that you enjoy TUGGO and find it useful for managing your website.  If there is anything that you think should be added, removed, or changed within the TUGGO package we reccomend that you contact us as soon as possible so that it can be implemented in the nearest benchmark release.  Enjoy!
	
	<br/><br/>
	
	<div style="text-align: center; padding: 5px; background: #f3f3f3; text-align: right; ">
		<a href="http://tuggo.org"><img src="../admin/tuggo2.png" alt="" style="width: 150px;" /></a>
	</div>




<?php } ?>

</div>

<br/>
<div id="adminfooter">
		<table class="ii" cellpadding="0" cellspacing="0" style="width: 800px; background: #F5F5F5; margin-left: auto; margin-right: auto;">

			<tr>
				<td class="iileft">
					<a href="http://tuggo.org"><img src="../admin/tuggo3.png" alt="TUGGO" style="height: 30px;" /></a>
				</td>
				<td class="iiright" style="padding-left: 10px;">
					&nbsp;
				</td>
			</tr>
		</table>
</div>